home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC_Samples / modeless / modeldlg.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  4.1 KB  |  176 lines

  1. // modeldlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "modeless.h"
  6. #include "adderdlg.h"
  7. #include "modeldlg.h"
  8.   
  9. #ifdef _debug
  10. #undef this_file
  11. static char based_code THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CAboutDlg dialog used for App About
  16.  
  17. class CAboutDlg : public CDialog
  18. {
  19. public:
  20.     CAboutDlg();
  21.  
  22. // Dialog Data
  23.     //{{AFX_DATA(CAboutDlg)
  24.     enum { IDD = IDD_ABOUTBOX };
  25.     //}}AFX_DATA
  26.  
  27. // Implementation
  28. protected:
  29.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  30.     //{{AFX_MSG(CAboutDlg)
  31.     virtual BOOL OnInitDialog();
  32.     //}}AFX_MSG
  33.     DECLARE_MESSAGE_MAP()
  34. };
  35.  
  36. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  37. {
  38.     //{{AFX_DATA_INIT(CAboutDlg)
  39.     //}}AFX_DATA_INIT
  40. }
  41.  
  42. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  43. {
  44.     CDialog::DoDataExchange(pDX);
  45.     //{{AFX_DATA_MAP(CAboutDlg)
  46.     //}}AFX_DATA_MAP
  47. }
  48.  
  49. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  50.     //{{AFX_MSG_MAP(CAboutDlg)
  51.         // No message handlers
  52.     //}}AFX_MSG_MAP
  53. END_MESSAGE_MAP()
  54.  
  55. /////////////////////////////////////////////////////////////////////////////
  56. // CAboutDlg message handlers
  57.  
  58. BOOL CAboutDlg::OnInitDialog() 
  59. {
  60.     CDialog::OnInitDialog();
  61.     CenterWindow();    
  62.     return TRUE; 
  63. }
  64.  
  65. /////////////////////////////////////////////////////////////////////////////
  66. // CMainDlg dialog
  67.  
  68. CMainDlg::CMainDlg(CWnd* pParent /*=NULL*/)
  69.     : CDialog(CMainDlg::IDD, pParent)
  70. {
  71.     //{{AFX_DATA_INIT(CMainDlg)
  72.         // NOTE: the ClassWizard will add member initialization here
  73.     //}}AFX_DATA_INIT
  74.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  75.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  76.     m_pModeless = NULL;
  77. }
  78.  
  79. void CMainDlg::DoDataExchange(CDataExchange* pDX)
  80. {
  81.     CDialog::DoDataExchange(pDX);
  82.     //{{AFX_DATA_MAP(CMainDlg)
  83.         // NOTE: the ClassWizard will add DDX and DDV calls here
  84.     //}}AFX_DATA_MAP
  85. }
  86.  
  87. BEGIN_MESSAGE_MAP(CMainDlg, CDialog)
  88.     //{{AFX_MSG_MAP(CMainDlg)
  89.     ON_WM_SYSCOMMAND()
  90.     ON_WM_PAINT()
  91.     ON_WM_QUERYDRAGICON()
  92.     //}}AFX_MSG_MAP
  93. END_MESSAGE_MAP()
  94.  
  95. /////////////////////////////////////////////////////////////////////////////
  96. // CMainDlg message handlers
  97.  
  98. BOOL CMainDlg::OnInitDialog()
  99. {
  100.     CDialog::OnInitDialog(    );
  101.  
  102.     // Add "About..." menu item to system menu.
  103.  
  104.     // IDM_ABOUTBOX must be in the system command range.
  105.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  106.     ASSERT(IDM_ABOUTBOX < 0xF000);
  107.  
  108. //    CMenu* pSysMenu = GetSystemMenu(FALSE);
  109. //    CString strAboutMenu;
  110. //    strAboutMenu.LoadString(IDS_ABOUTBOX);
  111. //    if (!strAboutMenu.IsEmpty())
  112. //    {
  113. //        pSysMenu->AppendMenu(MF_SEPARATOR);
  114. //        pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  115. //    }
  116.     
  117.     return TRUE;  // return TRUE  unless you set the focus to a control
  118. }
  119.  
  120. void CMainDlg::OnSysCommand(UINT nID, LPARAM lParam)
  121. {
  122.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  123.     {
  124.         CAboutDlg dlgAbout;
  125.         dlgAbout.DoModal();
  126.     }
  127.     else
  128.     {
  129.         CDialog::OnSysCommand(nID, lParam);
  130.     }
  131. }
  132.  
  133. // If you add a minimize button to your dialog, you will need the code below
  134. //  to draw the icon.  For MFC applications using the document/view model,
  135. //  this is automatically done for you by the framework.
  136.  
  137. void CMainDlg::OnPaint() 
  138. {
  139.     CDialog::OnPaint();
  140. }
  141.  
  142. // The system calls this to obtain the cursor to display while the user drags
  143. //  the minimized window.
  144. HCURSOR CMainDlg::OnQueryDragIcon()
  145. {
  146.     return (HCURSOR) m_hIcon;
  147. }
  148.  
  149. void CMainDlg::OnOK() 
  150. {
  151.     // if our modeless child isn't already up, create it and display it
  152.     // otherwise, just set focus to it
  153.  
  154.     if (m_pModeless == NULL)
  155.     {
  156.         m_pModeless = new CAdderDialog(this);
  157.         if (m_pModeless->Create() == TRUE)
  158.             GetDlgItem(IDOK)->EnableWindow(FALSE);
  159.     }
  160.     else
  161.         m_pModeless->SetActiveWindow();
  162. }
  163.  
  164.  
  165. void CMainDlg::BoxDone()
  166. {
  167.     // this function is called by the modeless dialog as it terminates
  168.     // just reset our pushbutton to be enabled again.
  169.     // I _don't_ delete the MFC CDialog object because the dialog's own
  170.     // code will do that.
  171.     
  172.     m_pModeless = NULL;
  173.     // don't delete m_pModeless; !
  174.     GetDlgItem(IDOK)->EnableWindow();
  175. }
  176.